package com.example.yiwei.crm.json;

import com.example.yiwei.crm.entity.CustomerMessageEntity;
import com.example.yiwei.crm.util.NetWorkUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/15.
 */

public class workbenchJson {
    public static List<CustomerMessageEntity> query_need_contact_message(String url, String para){
        String result= NetWorkUtils.getCount(url,para);
        List<CustomerMessageEntity> list;
        CustomerMessageEntity customer;
        try {
            JSONObject object=new JSONObject(result);
            String boolen=object.getString("boolean");
            if ("success".equals(boolen)) {
                list=new ArrayList<>();
                JSONArray array = object.getJSONArray("list");
                for (int i=0;i<array.length();i++){
                    customer=new CustomerMessageEntity();
                    JSONObject json=array.getJSONObject(i);
                    //状态
                    if (json.has("KAA27")){
                        customer.setFollw_state(json.getInt("KAA27"));
                    }
                    //客户名
                    if (json.has("KAA02")){
                        customer.setClient_name(json.getString("KAA02"));
                    }
                    //电话
                    if (json.has("KLA06")){
                        customer.setPhone_Number(json.getString("KLA06"));
                    }
                    list.add(customer);
                }
                return list;
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }
}
